<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/common.css">
    <link rel="stylesheet" href="/css/investResult.css">
    <script type="text/javascript" src="/js/assets/config.js"></script>
    <script type="text/javascript" src="/js/assets/require.js" data-main="/js/guide"></script>
    <script type="text/javascript" src="/js/assets/jquery-3.1.0.min.js"></script>
</head>
<body>
<#include "/include/header.ftl">
    <div class="invest_container">
        <div class="invest_banner">
            <div class="signMark"></div>
            <div id="result"></div>
            <div class="contentShow" style="margin-top: 60px;">
                <div class="content listView account"></div>
                <div class="content accountNum" style="text-align: right"></div>
            </div>
            <div style="clear: both;"></div>
            <div class="contentShow" style="margin-top: 42px;">
                <div class="content listView status"></div>
                <div class="content statusMes" style="text-align: right"></div>
            </div>
            <div style="clear: both;"></div>
            <a href="/item/investmentList?0?1">
                <div class="button ">

                </div>
            </a>
            <input type="hidden" id="orderId" readonly name="method" value="${orderId}"/>

        </div>
    </div>

<#include "/include/footer.ftl">
<#include "/include/smalldetails.ftl">
</body>
<script>
    var orderId = $("#orderId").val();
    var queryCount = 0;
    window.onload=function(){
        getResult(orderId);
    };
    function getResult(orderId) {
        if(queryCount >= 5){
            return;
        }
        $.ajax({
            type: 'post',
            url: "/return/notice/getInvestResult",
            data:{orderId : orderId},
            dataType: 'json',
            success: function(data) {
                $('.signMark').children().remove();
                $('#result').children().remove();
                $('.content').children().remove();
                $('.button').children().remove();
                if(data.result == 'pending'){
                    $('.signMark').append("<img src='/img/invest/pending.png'/>");
                    $("#result").html("处理中");
                    $(".account").html("投资金额");
                    $(".accountNum").html(data.investAmount+"元");
                    $(".status").html("投资状态");
                    $(".statusMes").html("已提交银行处理");
                    $(".button").html("查看详情").addClass('btnStyle');
                    setTimeout("getResult(orderId)",1000);
                    queryCount++;
                }else if(data.result == 'fail'){
                    $('.signMark').append("<img src='/img/invest/fail.png'/>");
                    $("#result").html("投资失败");
                    $(".account").html("投资金额");
                    $(".accountNum").html(data.investAmount+"元");
                    $(".status").html("失败原因");
                    $(".statusMes").html(data.messageText);
                    $(".button").html("继续理财").addClass('btnStyle');

                }else{
                    $('.signMark').append("<img src='/img/invest/success.png'/>");
                    $("#result").html("处理成功");
                    $(".account").html("投资金额");
                    $(".accountNum").html(data.investAmount+"元");
                    $(".status").html("投资状态");
                    $(".statusMes").html("投资成功");
                    $(".button").html("查看详情").addClass('btnStyle');
                }
            },
            error: function(e) {

            }
        });


    };
    function getQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    };

    //返回主页面
    function go(){
        window.location.href="/item/investmentList?0?1";
    }
</script>
</html>

